package com.dotto.atos.fragments;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.dotto.atos.R;
import com.dotto.atos.models.Announcement;
import com.dotto.atos.services.actions.AnnouncementService;
import com.dotto.atos.ui.AnnouncementListAdapter;
import com.dotto.atos.utils.MessageUtil;

public class AnnouncementsFragment extends Fragment {
	public static final String TAG = "AnnouncementsFragment";
	private View fragmentView;
	private Activity mActivity;
	@SuppressWarnings("unused")
	private AnnouncementsFragment instance;

	@SuppressWarnings("unused")
	private MessageUtil messageUtil;

	private AnnouncementService announcementService;

	private ListView lvAnnouncementList;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if (fragmentView == null) {
			fragmentView = inflater.inflate(R.layout.fragment_announcements,
					container, false);
		} else {
			((ViewGroup) fragmentView.getParent()).removeView(fragmentView);
		}
		mActivity = this.getActivity();
		instance = this;
		messageUtil = new MessageUtil(mActivity);
		announcementService = new AnnouncementService();
		initView();
		return fragmentView;
	}

	public void initView() {
		if (fragmentView != null) {
			lvAnnouncementList = (ListView) fragmentView
					.findViewById(R.id.lv_announcement_list);

			Announcement[] list = announcementService.getAnnouncementList();
			lvAnnouncementList.setAdapter(new AnnouncementListAdapter(
					mActivity, list));
		}
	}

}
